﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <link th:href="@{/css/menu.css}" rel="stylesheet"/>
    <style>
        .layui-table-cell {
            height: auto;
            text-align: left;
            line-height: normal;
            overflow: visible;
        }

        .layui-table-view .layui-table {
            width: 100%;
        }

        .layui-table-cell .title {
            padding: 5px 0;
        }

        .layui-table-cell .layui-row {
            line-height: 20px;
        }

        .layui-table-cell .layui-col-md8 {
            color: #ccc;
            font-size: 12px;
        }

        .layui-table-header {
            display: none;
        }

    </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-side" style="background: #f5f5f5;">
        <div class="layui-row " style="padding: 5px 10px;border-bottom: 1px solid #ccc;">
            <div class="layui-col-md6" style="line-height: 30px;">
                所有项目
            </div>
            <div class="layui-col-md6" style="text-align: right;line-height: 30px;">
                <a data-id="2" class="layui-btn layui-btn-normal layui-btn-xs action-project_add">新增项目</a>
            </div>
        </div>
        <div class="" id="project-data"></div>
    </div>
    <div class="layui-body" style="top: 0px;left: 250px;" id="layui-body-note">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="margin: 0px;">
            <ul class="layui-tab-title" style="text-align: center;">
                <li class="layui-this workitem" data-id="attach">资料</li>
                <li class="workitem" data-id="note">笔记</li>
                <li class="workitem" data-id="task">任务</li>
                <li class="workitem" data-id="daily">日报</li>
                <li class="workitem" data-id="weekly">周报</li>
                <li class="workitem" data-id="user">项目成员</li>
            </ul>
            <div class="layui-tab-content" style="top: 43px;padding: 0px;">
                <div class="layui-tab-item  layui-show" id="layui-tab-body">
                </div>
            </div>
        </div>

    </div>
</div>
<!-- layui规范化用法 -->
<script type="text/javascript">
    var defTab = "attach";
    /*加载某个标签的内容*/
    function loadTab() {
        workUtils.html({
            url: "../web/cloud/cloudwork_" + defTab + ".html",
            id: "layui-tab-body"
        });
    }
    /*单击Tab标签显示内容*/
    workUtils.onclick(".workitem", function (c) {
        var id = $(c).attr("data-id");
        defTab = id;
        loadTab();
    });
    /*显示菜单*/
    workUtils.onclick(".layui-icon-menu", function (c) {
        $(".widget-menu").hide();
        $(c).next().toggle();
        return false;
    });
    /*点击一行*/
    workUtils.onclick(".layui-rowitem", function (c) {
        var id = $(c).attr("data-id");
        workUtils.put("projectId", id);
        workUtils.toggle("#project-data .layui-rowitem-active", "layui-rowitem-active", c);
        try {
            loadDefaultData();
        } catch (e) {
        }
    });
    /*添加项目*/
    workUtils.onclick(".action-project_add", function (e) {
        workUtils.open({url: "../web/project/add.html", title: "添加项目", width: "600px"}, function () {
            loadProject();
        });
    });
    /*编辑项目*/
    workUtils.onclick(".action-project_edit", function (c) {
        var id = $(c).attr("data-id");
        workUtils.put("id", id);
        workUtils.open({url: "../web/project/add.html", title: "修改项目", width: "600px"}, function () {
            loadProject();
        });
    });
    /*删除项目*/
    workUtils.onclick(".action-project_delete", function (c) {
        var id = $(c).attr("data-id");
        workUtils.delete('../project/delete/' + id, function () {
            loadProject();
        },"确定解散项目吗?");
    });
    /*项目信息*/
    workUtils.onclick(".action-project_setting", function (c) {
        var id = $(c).attr("data-id");
        workUtils.put("id", id);
        workUtils.open({url: "../web/project/setting.html", title: "项目信息", width: "600px"});
    });
    /*项目统计*/
    workUtils.onclick(".action-project_stat", function (c) {
        var id = $(c).attr("data-id");
        workUtils.put("id", id);
        workUtils.open({url: "../web/project/stat.html", title: "项目统计", width: "600px"});
    });
    /*项目统计*/
    workUtils.onclick(".action-project_move", function (c) {
        var id = $(c).attr("data-id");
        workUtils.put("id", id);
        workUtils.open({url: "../web/project/move.html", title: "项目移交", width: "600px"});
    });
    /*加载项目列表*/
    function loadProject() {
        workUtils.ajaxGet('../project/list', {}, function (data) {
            var html = '<div>';
            if (data.length > 0) {
                workUtils.put("projectId", data[0].id);
                loadTab();
            }
            var cla = "layui-rowitem-active";
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                html += '<div class="layui-row layui-rowitem '+cla+'" data-id="' + item.id + '">';
                html += '<div class="layui-col-md8" style="line-height: 30px;">';
                if(item.hasRole){
                    html += '<i class="fa fa-user-secret"></i>';
                }else{
                    html += '<i class="fa fa-user"></i>';
                }
                html += item.name;
                html += "</div>";
                if(item.hasRole){
                    html += workUtils.buildMenu1(item.id, {
                        project_edit: "编辑项目", project_delete: "解散项目", split: "", project_move: "项目移交", split: "", project_setting: "项目信息", project_stat: "项目统计"
                    });
                }
                html += "</div>";
                cla = "";
            }
            html += '</div>';
            $('#project-data').html(html);
        })
    }
    /*加载页面的时候加载项目*/
    $(document).ready(function () {
        loadProject();
    });

</script>
</body>
</html>